<template>
  <div>
    <Card>
      <Table
        :data="tableData"
        :columns="columns"
        stripe
        border
        class="marginB10"
        :loading="loading"
        :height="$app.winHeight-185"
      ></Table>
      <Page
        :total="total"
        show-sizer
        show-total
        show-elevator
        size="small"
        :page-size="pageSize"
        :page-size-opts="$app.pageAll.pageSizeOpts"
        :current="page"
        @on-change="loadMore"
        @on-page-size-change="changePageSize"
      ></Page>

    </Card>
  </div>
</template>


<script>
  export default {
    name: 'moneyList',
    components: {},
    data () {

      let data = {
        tableData: [],
        columns: []
      };
      //分页相关
      let tool = {
        loading: true, //加载时显示转转
        total: 0, // 所有数据条数
        page: 1, // 当前页数
        pageSize: $app.pageAll.pageSize, // 默认数据返回条数
      };

      return Object.assign(data, tool); // 对象合并

    },
    mounted () {
      this.getData();
    },

    methods:{
      getData(){
        let {
          pageSize,
          page
        }=this;
        
        // 清空原本的数据
        this.loading=true;
        this.columns=[];
        this.tableData=[];
        
        // 获取数据 type流水类型,0全部，1充值,2消费,3收益,4收益提现,41提现拒绝返还金额,5退款;
        $ajax.lb_getPartnerloWater({type:0,page,pageSize},({data}) => {
          this.loading=false;

          this.columns=[
            {
              title: " ",
              type: "index",
              width: 30,
              align: "center ",
              className: "goOnTxt c999"
            },
            {
              title: "订单编号",
              key: "order_no",
              className: "goOnTxt",
              resizable: true,
              width:220
            },
            {
              title: '时间',
              key: "created_at",
              className: "goOnTxt",
              resizable: true,
              width:160
            },
            {
              title: '金额(元)',
              key: "money",
              className: "goOnTxt",
              resizable: true,
              width:100,
              render: (h, params) => {
                let type=params.row.type;//1充值:+,2消费:-,3收益:+,4收益提现:-,41提现拒绝返还金额:+,5退款:+
                let money=parseFloat(params.row.money);
                let out=[];
                if(money>0){
                  out.push(
                    h(
                      "span",
                      {
                        class: "  marginR5 f_bold "+(type==2||type==4?' cBlue':' cRed')
                      },
                      ((type==2||type==4)?'-':'+')
                    )
                  );
                }
                out.push(
                  h(
                    "span",
                    money
                  )
                );
                return out;
              }
            },
            {
              title: '猫币',
              className: "goOnTxt",
              resizable: true,
              width:100,
              render: (h, params) => {
                let type=params.row.type;//1充值:+,2消费:-,3收益:+,4收益提现:-,41提现拒绝返还金额:+,5退款:+
                let currency=parseFloat(params.row.currency);
                let out=[];
                if(currency>0){
                  out.push(
                    h(
                      "span",
                      {
                        class: "  marginR5 f_bold "+(type==2||type==4?' cBlue':' cRed')
                      },
                      ((type==2||type==4)?'-':'+')
                    )
                  );
                }
                out.push(
                  h(
                    "span",
                    currency
                  )
                );
                return out;
              }
            },
            {
              title: '剩余金额(元)',
              className: "goOnTxt",
              resizable: true,
              width:120,
              render: (h, params) => {
                let out = [
                  h(
                    "span",
                    parseFloat(params.row.after_balance)
                  )
                ];
                return out;
              }
            },
            {
              title: '剩余猫币',
              className: "goOnTxt",
              resizable: true,
              width:100,
              render: (h, params) => {
                let out = [
                  h(
                    "span",
                    parseFloat(params.row.after_currency)
                  )
                ];
                return out;
              }
            },
            {
              title: '支付方式',
              key: "order_pay_type",
              className: "goOnTxt",
              resizable: true,
              width:120
            },
            {
              title: '余额说明',
              key: "remark",
              className: "goOnTxt",
              resizable: true
            }
          ];

          this.tableData = data.list;
          this.total = data.total;
        })
      },
      // 加载更多
      loadMore (page) {
        this.page = page;
        this.getData()
      },
      // 数据返回条
      changePageSize(pageSize) {
        this.page = 1;
        this.pageSize = pageSize;
        this.getData()
      },
    }
  }
</script>

